package com.nebula.util;

import java.text.DecimalFormat;

public class FileUtil {
	public static String byteCountToDisplaySize(long size) {  

        String displaySize;  
        
        long ONE_GB = 1073741824;
        long ONE_MB = 1048576;
        long ONE_KB = 1024;
        DecimalFormat df = new DecimalFormat("0.00");
        if (size / ONE_GB > 0) {  
        	
            displaySize = df.format((float)size / ONE_GB) + "G";  

        } else if (size / ONE_MB > 0) {  

            displaySize = df.format((float)size / ONE_MB) + "M";  

        } else if (size / ONE_KB > 0) {  

            displaySize = df.format((float)size / ONE_KB) + "KB";  

        } else {  

            displaySize = String.valueOf(size) + "B";  

        }  

        return displaySize;  

    }
	
	public static String unreservedDecimalPoint(long size){
		String displaySize;  
        
        long ONE_GB = 1073741824;
        long ONE_MB = 1048576;
        long ONE_KB = 1024;
        DecimalFormat df = new DecimalFormat("0");
        if (size / ONE_GB > 0) {  
        	
            displaySize = df.format((float)size / ONE_GB) + "G";  

        } else if (size / ONE_MB > 0) {  

            displaySize = df.format((float)size / ONE_MB) + "M";  

        } else if (size / ONE_KB > 0) {  

            displaySize = df.format((float)size / ONE_KB) + "KB";  

        } else {  

            displaySize = String.valueOf(size) + "B";  

        }  

        return displaySize; 
	}
}
